package xyz.hellothomas.sftp.client.autoconfigure;

import lombok.extern.slf4j.Slf4j;
import xyz.hellothomas.sftp.client.core.SftpTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Thomas
 * @date 2022/2/21 22:33
 * @description
 * @version 1.0
 */
@Slf4j
public class SftpUtil {
    private static final Map<String, SftpTemplate> SFTP_TEMPLATE_MAP = new HashMap<>();
    private static SftpTemplate singleSftpTemplate;

    private SftpUtil() {
        throw new IllegalStateException("Utility class");
    }

    public synchronized static void initSftpTemplateMap(Map<String, SftpTemplate> sftpTemplateMap) {
        if (!sftpTemplateMap.isEmpty()) {
            sftpTemplateMap.forEach((k, v) -> SFTP_TEMPLATE_MAP.put(k, v));
        }
        if (sftpTemplateMap.size() == 1) {
            sftpTemplateMap.forEach((k, v) -> singleSftpTemplate = v);
        }
        log.debug("initSftpTemplateMap");
    }
}
